package com.jjc.android.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jjc.android.R
import com.jjc.android.entity.DeviceDto
import com.jjc.android.view.CommonKt.appendDeviceName

class MyDeviceAdapter : BaseQuickAdapter<DeviceDto,BaseViewHolder>(R.layout.item_my_device) {

    override fun convert(helper: BaseViewHolder, item: DeviceDto) {
        helper.addOnClickListener(R.id.detailTxt,R.id.right_view,R.id.drag_item)
        helper.setText(R.id.productNameTxt,item.deviceName)
        helper.setText(R.id.resultTxt, String.format("%s：%s",mContext.getString(R.string.device_sn),item.bhmohipntdlpc61m))
        helper.setText(R.id.detailTxt,String.format("%s：%d",mContext.getString(R.string.bind_account_txt),item.accounts.let { if(it.isNullOrEmpty()) 0 else it.size }))
    }

    override fun setNewData(data: List<DeviceDto>?) {
        super.setNewData(data.appendDeviceName(false))
    }

    override fun addData(newData: MutableCollection<out DeviceDto>) {
        mData.addAll(newData)
        setNewData(mData)
    }

}